package cli

import (
	"fmt"
	"wire/internal/data"

	"gitee.com/go-mod/framework/config"
	"github.com/spf13/pflag"
)

type VerCli struct {
	data *data.Data
	flag *flags
}

type flags struct {
	stream string
	group  string
}

func flagParse() *flags {
	// 定义命令行参数
	f := &flags{}
	pflag.StringVarP(&f.stream, "stream", "s", "", "")
	pflag.StringVarP(&f.group, "group", "g", "", "")
	// 解析命令行参数
	pflag.Parse()
	return f
}

func NewVerCli(data *data.Data) *VerCli {
	return &VerCli{
		data: data,
		flag: flagParse(),
	}
}

// Version go run . version --stream s1 -g g1
func (c *VerCli) Version() func() {
	return func() {
		fmt.Println(config.GetString("app.version"))
		fmt.Println("Stream:", c.flag.stream)
		fmt.Println("Group:", c.flag.group)
		fmt.Printf("flags: %+v\n", c.flag)
	}
}
